import axios from 'axios'
import cookie from 'js-cookie'

const request = axios.create({
    timeout: 3000,
    timeoutErrorMessage: '请求超时'
})

// 请求拦截
request.interceptors.request.use((config) => {
    if(cookie.get('token')) {
        config.headers.authorization = cookie.get('token')
    }

    return config
}, (err) => {
    return Promise.reject(err)
})


// 响应拦截
request.interceptors.response.use(config => {
    return config.data
}, err => {
    return Promise.reject(err)
})

export default request;